<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<style>
    .deleteImg {
        width: 20px;
        position: relative;
        top: -40px;
        /*left: 100px;*/
        cursor: pointer;
        display: none;
    }

    .startImg {
        width: 100px;
        height: 100px;
    }
</style>
<div class="main-content">
    <div class="box box-main">
        <form id="reportOrderForm" model="post" action="<c:url value="/web/admin/repairOrder/addOrUpdate.action"/>"
              enctype="multipart/form-data"
              method="post" class="form-horizontal">
            <div class="box-body">
                <div class="form-unit">基本信息</div>
                <input type="hidden" name="id" value="${repairOrder.id}"/>
                <input type="hidden" name="assignTypeEnum" value="${repairOrder.assignTypeEnum}"/>
                <input type="hidden" name="auditLevel" value="${repairOrder.auditLevel}"/>
                <input type="hidden" name="transfer" value="${repairOrder.transfer}"/>
                <input type="hidden" name="faultReason" value="${repairOrder.faultReason}"/>
                <input type="hidden" name="unrepairReason" value="${repairOrder.unrepairReason}"/>
                <input type="hidden" name="assign" value="${repairOrder.assign}"/>
                <input type="hidden" name="level" value="${repairOrder.level}"/>
                <input type="hidden" name="measure" value="${repairOrder.measure}"/>
                <input type="hidden" name="repairFinishTime1" value="${repairOrder.repairFinishTime}"/>
                <input type="hidden" name="presenceTime1" value="${repairOrder.presenceTime}"/>
                <input type="hidden" name="spareParts" value="${repairOrder.spareParts}"/>
                <input type="hidden" name="flow" value="${repairOrder.flow}"/>
                <input type="hidden" name="inRepairScope" value="${repairOrder.inRepairScope}"/>
                <input type="hidden" name="flowName" value="${repairOrder.flowName}"/>
                <input type="hidden" name="telephoneUserId" value="${repairOrder.telephoneUser.id}"/>
                <input type="hidden" name="latitude" value="${repairOrder.latitude}"/>
                <input type="hidden" name="longitude" value="${repairOrder.longitude}"/>
                <input type="hidden" name="troubleCatId" value="${repairOrder.troubleCat.id}"/>
                <input type="hidden" name="workingHours" value="${repairOrder.workingHours}"/>
                <input type="hidden" name="telephone" value="${repairOrder.telephone}"/>
                <input type="hidden" name="totalWorkingHours" value="${repairOrder.totalWorkingHours}"/>
                <input type="hidden" name="repairOrderStatusEnum" value="${repairOrder.repairOrderStatusEnum}"/>
                <input type="hidden" name="recording" value="${repairOrder.resource.id}"/>
                <input type="hidden" name="receiveUserId" value="${repairOrder.receiveUser.id}"/>
                <input type="hidden" name="chargeUserId" value="${repairOrder.chargeUser.id}"/>
                <input type="hidden" name="createDate1"
                       value="<fmt:formatDate value="${repairOrder.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
                <input type="hidden" name="repairOrderType" id="repairOrderType" value="${repairOrderType}"/>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <div class="control-label col-sm-6">
                                <input type="radio" name="reportType" value="commonRepair" id="commonRepair"
                                       onchange="is400Repair(false)"
                                       <c:if test="${repairOrderType == 'COMMON_ORDER'||repairOrderType==null}">checked="checked"</c:if>
                                >普通报修/设备报修&nbsp;&nbsp;&nbsp;
                            </div>
                            <div class="control-label col-sm-6">
                                <input type="radio" name="reportType" value="_400Repair" id="_400Repair"
                                       onchange="is400Repair(true)"
                                       <c:if test="${repairOrderType == '_400_ORDER'}">checked="checked"</c:if>
                                >400报修&nbsp;&nbsp;&nbsp;
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <%--<c:if test="${repairOrderType!= '_400_ORDER'}">--%>
                        <%--<div class="col-xs-6" id="organization">--%>
                            <%--<div class="form-group">--%>
                                <%--<label class="control-label col-sm-4" title="">--%>
                                    <%--所属部门：<i class="fa icon-question hide"></i></label>--%>
                                <%--<div class="col-sm-8">--%>
                                    <%--<input id="selectOrganizationId" name="selectOrganizationId" class="form-control">--%>
                                <%--</div>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                    <%--</c:if>--%>

                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                报修来源：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="repairSourceEnum" value="客户报修" readonly="readonly"
                                       class="form-control required">
                            </div>
                        </div>
                    </div>
                        <div class="col-xs-6">
                            <div class="form-group">
                                <label class="control-label col-sm-4" title="">
                                    维修单类型：<i class="fa icon-question hide"></i></label>
                                <div class="col-sm-8">
                                    <input id="selectRepairTypeId" name="selectRepairTypeId"
                                           class="form-control required">
                                </div>
                            </div>
                        </div>
                </div>

                <div class="row">

                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                报修人：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="selectUserId" name="selectUserId" class="form-control required">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title=""><span class='repair required'
                                                                                 style="display: none">*</span>报修等级：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="selectReportLevelId" name="selectReportLevelId"
                                       class="form-control required">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                是否维修范围：<i class="fa icon-question hide "></i></label>
                            <div class="col-sm-8 switch">
                                <input type="checkbox" class="form-control" id="inRoutingScope"
                                       name="inRoutingScope"
                                       <c:if test="${repairOrder.inRoutingScope==true|| repairOrder.inRoutingScope==null}">checked</c:if>

                                       style="margin-top: auto;margin-bottom: auto"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" id="showUpload">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                接线人：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectTelephoneUser" id="selectTelephoneUser" name="selectTelephoneUser"
                                       class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                400主叫号码：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectSrc" id="selectSrc" name="selectSrc" class="form-control ">
                                <input type="hidden" id="src" value="0">
                            </div>
                        </div>
                    </div>


                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                400添加录音：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input path="selectRecordingPath" id="selectRecordingPath"
                                       name="selectRecordingPath"
                                       class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                客户报修人：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="customer" name="customer"  value="${repairOrder.customer}"
                                       class="form-control ">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title=""><span class="required">*</span>
                                客户报修电话：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input type="tel" id="callNumber" name="callNumber" value="${repairOrder.callNumber}"
                                       class="form-control">
                            </div>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title=""><span class='repair required'
                                                                                 style="display: none">*</span>设备编号：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="selectFacilityId" name="selectFacilityId" class="form-control">
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title=""><span class='repair required'
                                                                                 style="display: none">*</span>报修设备：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="facilityName" name="facilityName" readonly="readonly" class="form-control">
                            </div>
                        </div>
                    </div>

                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">报修专业：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="majorName" name="majorName" class="form-control" readonly="readonly">

                            </div>
                        </div>
                    </div>

                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                报修区域：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="selectAreaId" name="selectAreaId" class="form-control ">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4"><span class="required">*</span>报修内容：</label>
                            <div class="col-sm-8 controls">
                                <textarea htmlEscape="false" rows="4" maxlength="400" name="reportContent"
                                          class="form-control required">${repairOrder.reportContent}</textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title=""><span class='repair required'
                                                                                 style="display: none">*</span>报修地址：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                <textarea htmlEscape="false" rows="4" maxlength="400" name="reportAddress" id="reportAddress"
                          class="form-control ">${repairOrder.reportAddress}</textarea>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title=""><span class='repair required'
                                                                                 style="display: none">*</span>报修照片：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <div>
                                    <img class="startImg" id="img1" src="<c:url value="/resources/images/2.png" />"
                                         onclick="$('#pic1').click();"/>
                                    <img class="deleteImg" id="delete1"
                                         src="<c:url value="/resources/images/delete.png"/>"
                                         onclick="delectImg(1)"/>
                                    <input type="file" style="display: none;" name="pic1" id="pic1"
                                           onchange="getimgload(1)"/>
                                    <input type="hidden" id="sImg1" name="sImg1" value="0"/><%--判断有没有变更图片用的 变了就为1 不变就为0--%>

                                    <img class="startImg" id="img2" src="<c:url value="/resources/images/2.png" />"
                                         onclick="$('#pic2').click();"/>
                                    <img class="deleteImg" id="delete2"
                                         src="<c:url value="/resources/images/delete.png"/>"
                                         onclick="delectImg(2)"/>
                                    <input type="file" style="display: none;" name="pic2" id="pic2"
                                           onchange="getimgload(2)"/>
                                    <input type="hidden" id="sImg2" name="sImg2" value="0"/><%--判断有没有变更图片用的 变了就为1 不变就为0--%>

                                    <img class="startImg" id="img3" src="<c:url value="/resources/images/2.png" />"
                                         onclick="$('#pic3').click();"/>
                                    <img class="deleteImg" id="delete3"
                                         src="<c:url value="/resources/images/delete.png"/>"
                                         onclick="delectImg(3)"/>
                                    <input type="file" style="display: none;" name="pic3" id="pic3"
                                           onchange="getimgload(3)"/>
                                    <input type="hidden" id="sImg3" name="sImg3" value="0"/><%--判断有没有变更图片用的 变了就为1 不变就为0--%>

                                    <img class="startImg" id="img4" src="<c:url value="/resources/images/2.png" />"
                                         onclick="$('#pic4').click();"/>
                                    <img class="deleteImg" id="delete4"
                                         src="<c:url value="/resources/images/delete.png"/>"
                                         onclick="delectImg(4)"/>
                                    <input type="file" style="display: none;" name="pic4" id="pic4"
                                           onchange="getimgload(4)"/>
                                    <input type="hidden" id="sImg4" name="sImg4" value="0"/><%--判断有没有变更图片用的 变了就为1 不变就为0--%>

                                    <img class="startImg" id="img5" src="<c:url value="/resources/images/2.png" />"
                                         onclick="$('#pic5').click();"/>
                                    <img class="deleteImg" id="delete5"
                                         src="<c:url value="/resources/images/delete.png"/>"
                                         onclick="delectImg(5)"/>
                                    <input type="file" style="display: none;" name="pic5" id="pic5"
                                           onchange="getimgload(5)"/>
                                    <input type="hidden" id="sImg5" name="sImg5" value="0"/><%--判断有没有变更图片用的 变了就为1 不变就为0--%>
                                </div>


                            </div>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                完成审批流：<i
                                    class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <input id="selectCompleteAuditFlowId" name="selectCompleteAuditFlowId"
                                       class="form-control">
                            </div>
                        </div>
                    </div>
                </div>

                <div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <div class="form-group">
                                <label class="control-label col-sm-4" title="">
                                    所属企业：<i class="fa icon-question hide"></i></label>
                                <label class="control-label col-sm-8" style="text-align: left" title="">
                                    ${enterprise.enterpriseName}<i class="fa icon-question hide"></i></label>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

            <div class="box-footer">
                <div class="row">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-sm btn-primary" id="btnSubmit" οnclick="submitFunction">
                            <i class="fa fa-check" ></i>
                            保 存
                        </button>&nbsp;

                        <button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="closeView()"><i
                                class="fa fa-times"></i> 关 闭
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<script>





    function is400Repair(is400) {
        if (is400) {
            $('#repairOrderType').val('_400_ORDER');
            $('#showUpload').show();
            $("#repairEnterprise").show();
            // $("#organization").hide();
        } else {
            $('#repairOrderType').val('COMMON_ORDER');
            $('#showUpload').hide();
            $("#organization").show();
            $("#repairEnterprise").hide();
        }
    }


    function delectImg(id) {
        $("#sImg" + id).val('1');
        $("#pic" + id).val('');
        $("#img" + id).attr("src", "<c:url value="/resources/images/2.png" />");
        $("#delete" + id).hide();
    }


    $('#inRoutingScope').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info"
    });


    $('#facilityReport').bootstrapSwitch({
        onText: "是",
        offText: "否",
        onColor: "success",
        offColor: "info",
    });


    $("#reportOrderForm").validate({
        submitHandler: function (form) {
            // 武汉通用id
            var whtyId = '${signEnterpriseId}';
            // 当前企业id
            var nowId = '${enterprise.id}';
            // 武汉通用 400 保修必须要有审批流
            if( $('#repairOrderType').val()=='_400_ORDER' && selectCompleteAuditFlowId.getValue() == "" && whtyId == nowId ){
                    js.showMessage("请选择审批流");
                    return false;
            }

            if( $('#repairOrderType').val()=='_400_ORDER' && $("#callNumber").val()=='' ){
                js.showMessage("请输入客户报修电话",'提示');
                return false;
            }
            js.ajaxSubmitForm($(form), function (data) {
                if (data.status == Global.NO) {
                    closeView();
                    $('#dataGrid').dataGrid("refresh");
                }
            }, "json");
        }
    });










    function closeView() {
        layer.close(LayWin['wRepairOrder']);
    }

    var selectAreaId = $('#selectAreaId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/area/getAreaSelect.action?id=${repairOrder.reportArea.id}" />',
        queryParam: {},
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.reportArea.id}')
    });

    $(selectAreaId).on('selectionchange', function (e, m) {
        validateMagicReload();
    });

    var selectRepairEnterpriseId = $('#selectRepairEnterpriseId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/enterprise/getManyEnterpriseListMagic.action" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.enterprise.id}')
    });

    $(selectRepairEnterpriseId).on('selectionchange', function (e, m) {
        selectReportLevelId.clear(true);
        selectRepairTypeId.clear(true);
        selectFacilityId.clear(true);
        selectCompleteAuditFlowId.clear(true);
        selectAreaId.clear(true);


    });


    var selectRepairTypeId = $('#selectRepairTypeId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/dictInfo/getDictInfoListMagic.action?typeCode=REPAIR_TYPE" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.repairType.id}')
    });

    $(selectRepairTypeId).on('beforeload', function (e, m) {
        if (${enterprise.enterpriseName.equals("400center")}) {
            if (selectRepairEnterpriseId.getValue() == "") {
                js.showMessage("请选择报修企业！");
            } else {
                selectRepairTypeId.setDataUrlParams({"enterpriseId": selectRepairEnterpriseId.getValue() + ""});
            }
        }
    });

    var selectReportLevelId = $('#selectReportLevelId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/repairOrder/getRepairLevelListMagic.action" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.reportLevel.id}')
    });

    $(selectReportLevelId).on('beforeload', function (e, m) {
        if (${enterprise.enterpriseName.equals("400center")}) {
            if (selectRepairEnterpriseId.getValue() == "") {
                js.showMessage("请选择报修企业！");
            } else {
                selectReportLevelId.setDataUrlParams({"enterpriseId": selectRepairEnterpriseId.getValue() + ""});
            }
        }
    });


    var selectUserId = $('#selectUserId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/systemUser/getUserListMagic.action?id=${repairOrder.reportUser.id}" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.reportUser.id}')
    });
    var selectTelephoneUser = $('#selectTelephoneUser').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/systemUser/getUserListMagic.action?id=${repairOrder.reportUser.id}" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.reportUser.id}')
    });


    var selectFacilityId = $('#selectFacilityId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/facility/getFacilitySelectByCode.action?id=${repairOrder.facility.id}" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.facility.id}')
    });

    $(selectFacilityId).on('beforeload', function (e, m) {
        if (${enterprise.enterpriseName.equals("400center")}) {
            if (selectRepairEnterpriseId.getValue() == "") {
                js.showMessage("请选择报修企业！");
            } else {
                selectFacilityId.setDataUrlParams({"enterpriseId": selectRepairEnterpriseId.getValue() + ""});
            }
        }
    });

    $(selectFacilityId).on('selectionchange', function (e, m) {
        selectAreaId.clear(true);
        $.ajax({
            url: '<c:url value="/web/admin/facility/getAreaId.action" />',
            data: {"facilityId": selectFacilityId.getValue().toString()},
            success: function (result) {
                selectAreaId.setValue(magicSuggestValue(result.areaId));
                $("#facilityName").val(result.facilityName)
            }
        });
        $.ajax({
            url: '<c:url value="/web/admin/facility/getMajorName.action" />',
            data: {"facilityId": selectFacilityId.getValue().toString()},
            success: function (result) {
                $('#majorName').val(result.majorName);

            }
        });

        $.ajax({
            url: '<c:url value="/web/admin/facility/getPosition.action" />',
            data: {"facilityId": selectFacilityId.getValue().toString()},
            success: function (result) {
                $('#reportAddress').val(result.position);
            }
        });
    });

    var selectOrganizationId = $('#selectOrganizationId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/organization/getOrganizationListMagic.action?id=${repairOrder.organization.id}" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.organization.id}')
    });

    var selectCompleteAuditFlowId = $('#selectCompleteAuditFlowId').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/auditFlow/getAuditFlowSelect.action?type=complete&&flag=1" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.auditFlow.id}')
    });


    $(selectCompleteAuditFlowId).on('beforeload', function (e, m) {
        if (${enterprise.enterpriseName.equals("400center")}) {
            if (selectRepairEnterpriseId.getValue() == "") {
                js.showMessage("请选择报修企业！");
            } else {
                selectCompleteAuditFlowId.setDataUrlParams({"enterpriseId": selectRepairEnterpriseId.getValue() + ""});
            }
        }
    });


    var selectSrc = $('#selectSrc').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/repairOrder/getSrcSelect.action?id=${repairOrder.src}" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        required: true,
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${repairOrder.src}')
    });
    $(selectSrc).on('selectionchange', function (e, m) {
        $('#src').val(selectSrc.getValue()[0]);
        selectRecordingPath.clear(true);
    });


    var selectRecordingPath = $('#selectRecordingPath').magicSuggest({
        allowFreeEntries: false,
        data: '<c:url value="/web/admin/repairOrder/getRecordingPath.action?id=${repairOrder.recordingPath}" />',
        queryParam: 'q',
        valueField: "value",
        displayField: "text",
        maxSelection: 1,
        noSuggestionText: '',
        placeholder: '请选择',
        autoSelect: true,
        selectFirst: true,
        value: magicSuggestValue('${recording}')
    });

    $(selectRecordingPath).on('beforeload', function (e, m) {
        selectRecordingPath.setDataUrlParams({"src": $('#src').val()});
    });


    //初始化显示图片，根据报修类型显示必填项
    $(document).ready(function () {
        if (${repairOrderType == 'COMMON_ORDER'|| repairOrderType==null}) {
            is400Repair(false)
        } else {
            is400Repair(true)
        }
        if (${img1!=""}) {
            $("#img1").attr("src", "${img1}");
            $("#delete1").show();
        }
        if (${img2!=""}) {
            $("#img2").attr("src", "${img2}");
            $("#delete2").show();
        }
        if (${img3!=""}) {
            $("#img3").attr("src", "${img3}");
            $("#delete3").show();
        }
        if (${img4!=""}) {
            $("#img4").attr("src", "${img4}");
            $("#delete4").show();
        }
        if (${img5!=""}) {
            $("#img5").attr("src", "${img5}");
            $("#delete5").show();
        }
    });

    function delectImg(id) {
        $("#sImg" + id).val('1');//表示图片变更了（或者删掉了 总之不是原来的图片了）
        $("#pic" + id).val('');
        $("#img" + id).attr("src", "<c:url value="/resources/images/2.png" />");
        $("#delete" + id).hide();
    }

    function getimgload(id) {
        var obj = document.getElementById("pic" + id);
        var stuff = obj.value.match(/^(.*)(\.)(.{1,8})$/)[3];
        console.log(stuff);
        if (stuff != 'jpg' && stuff != 'png' && stuff != 'jpeg') {
            alert('图片类型不正确');
            return false;
        }
        //判断图片
        if (stuff == 'jpg' || stuff == 'png' || stuff == 'jpeg') {
            var file = document.getElementById("pic" + id).files[0];
            var reader = new FileReader();
            reader.onload = function (event) {
                if (!/image\/\w+/.test(file.type)) {
                    alert("文件必须为图片！");
                    return false;
                }
                src = event.target.result;
                $("#img" + id).attr("src", src);
            };
            reader.readAsDataURL(file);
        }
        $("#sImg" + id).val('1');//表示图片变更了（总之不是原来的图片了）
        $("#delete" + id).show();
    }


</script>


